import type { BaseEntity, ID, PageQuery, PageResult } from '#/api/common';

import { requestClient } from '#/api/request';

export interface SysConfig extends BaseEntity {
  configId: ID;
  configName: string;
  configKey: string;
  configValue: string;
  configType: string;
}

const baseUrl = `/sys_biz/sys_config`;

// 查询参数列表
export function listConfig(query: PageQuery) {
  return requestClient.get<PageResult<SysConfig>>(`${baseUrl}/list`, {
    params: query,
  });
}

// 查询参数详细
export function getConfig(configId: ID) {
  return requestClient.get<SysConfig>(`${baseUrl}/${configId}`);
}

// 根据参数键名查询参数值
export function getValueByKey(configKey: string) {
  return requestClient.get<string>(`${baseUrl}/key/${configKey}`);
}

// 新增参数配置
export function addConfig(data: any) {
  return requestClient.post(`${baseUrl}/add`, data);
}

// 修改参数配置
export function editConfig(data: any) {
  return requestClient.post(`${baseUrl}/edit`, data);
}

// 删除参数配置
export function delConfig(configId: ID) {
  return requestClient.post(`${baseUrl}/remove`, configId);
}

// 刷新参数缓存
export function refreshCache() {
  return requestClient.post(`${baseUrl}/refresh_cache`);
}
